﻿
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using Gift.Model.ENUM;
using System.Text;
using Gift.DAL;
using Gift.Model;


    public partial class admin_product_CardQuery : BaseAdmin
    {
        readonly dalCompany theCompany = new dalCompany();
        readonly DALAdminLogin theAdminLogin = new DALAdminLogin();
        readonly DALCardType theCardType = new DALCardType();

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if ((e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.DataRow))
            {
        
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {

                  
                        if (e.Row.Cells[2].Text == ((int)CardState.AlreadyOpen).ToString())
                        {
                            e.Row.Cells[2].Text = "已开卡";
                        }
                        else if (e.Row.Cells[2].Text == ((int)CardState.AlreadyUserd).ToString())
                        {
                            e.Row.Cells[2].Text = "已使用";
                        }
                        else if (e.Row.Cells[2].Text == ((int)CardState.AlreadyDisable).ToString())
                        {
                            e.Row.Cells[2].Text = "已失效";
                        }
                        else if (e.Row.Cells[2].Text == ((int)CardState.NoProduct).ToString())
                        {
                            e.Row.Cells[2].Text = "未生产";
                        }
                        else if (e.Row.Cells[2].Text == ((int)CardState.NoOpen).ToString())
                        {
                            e.Row.Cells[2].Text = "未激活";
                        }
                        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
                        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#efefef\"");
                    }
                 
            }
        }



        private void GridViewBind(string Sqlsort)
        {

            string sql = "select distinct C.CardCode,C.CardPrice,C.states,0 as userType, '订单号为：' +  OA.OrderCode as code  "
                       + " FROM DB_Card C  "
                       + "  join tbOrderAccount OA on C.Cardid = OA.Cardid "
                       + "  join DB_Order O on OA.OrderCode = O.OrderCode "
                       + " where c.CardCode = '" + this.cardcode.Value.Trim() + "' and C.states=2";
            string sql2 = " select distinct C.CardCode,C.CardPrice,C.states,1 as userType,MA.MemberId  as id, "
                        + "  '用户名为：' +(select memberlogin from DB_Member where MemberId = MA.MemberId) as code "
                       + " FROM DB_Card C "
                       + "  join tbMemberAccount MA on C.Cardid = MA.Cardid "
                       + " where c.CardCode = '" + this.cardcode.Value.Trim() + "' and C.states=2";
            string sql3 = " select *,2 as userType,'' as code from DB_Card "
                          + " where CardCode = '" + this.cardcode.Value.Trim() + "'";

            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count <= 0)
            {
                table = SQLAccess.GreatDs(sql2).Tables[0];
            }
            if (table.Rows.Count <= 0)
            {
                table = SQLAccess.GreatDs(sql3).Tables[0];
            }
            this.GridView1.DataSource = table.DefaultView;
            this.GridView1.DataBind();
          
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!base.IsPostBack)
            {       
                base.ValidateLoginRule(ERule.CardQuery);
                this.GridViewBind("");

            }
        }


        protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
        {
            this.GridViewBind("");
        }

    }